
'use strict';

const { Controller } = require('egg');

class HomeController extends Controller {
    async index() {
        let result = await this.ctx.service.station.index()
        this.ctx.body = {
            code: 200,
            message: "查询成功",
            data: result
        }
    }
    async create() {
        let result = await this.ctx.service.station.create(this.ctx.request.body)
        console.log(result.affectedRows, "result")
        if (result.affectedRows == 1) {
            this.ctx.body = {
                code: 200,
                message: '新增成功'
            }
        } else {
            this.ctx.body = {
                code: 400,
                message: '新增失败'
            }
        }

    }
    // 删除
    async destroy() {
        console.log(this.ctx.params)
        let result = await this.ctx.service.station.destroy(this.ctx.params)
        console.log(result.affectedRows, "result")
        if (result.affectedRows == 1) {
            this.ctx.body = {
                code: 200,
                message: '删除成功'
            }
        } else {
            this.ctx.body = {
                code: 400,
                message: '删除失败'
            }
        }

    }

}

module.exports = HomeController;
